#pragma once
#include <memory>
#include "Socket.hpp"
/*
    tcp服务器
*/
const uint16_t port = 8888;
enum class SERVER_TYPE
{
    SELECT_SER,
    POLL_SER,
    EPOLL_SER
};
class Server
{
public:
    using ptr = std::unique_ptr<Server>;
    Server()
    {}
    void InitServer()
    {   
        _listensock.Socket();
        _listensock.Bind(port);
        _listensock.Listen();
        ReuseAddr();
    }
    // 事件派发器 
    virtual void Dispatcher() = 0;
    // 端口复用
    void ReuseAddr()
    {
        int optval = 1;
        setsockopt(_listensock.Fd(),SOL_SOCKET,SO_REUSEADDR,&optval,sizeof(optval));
    }
    virtual ~Server()
    {}
protected:
    Sock _listensock;
    
};